<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!-- 게시물 수정 권한에 대한 상세 로직 설정 필요.
	 게시물 수정 권한을 받았을시 수정할수있는 범위 설정도 상의 필요
 -->

<script type="text/javascript">

$(function(){
	 $.ajax({
			type:"post",
			url:"${initParam.root}auction/findByCategory.do",
			datatype:"json",
			success:function(data){	
				 var BigClassList="<option value='${vo.bcvo.bigClassNo}'>--${vo.bcvo.bigClassName}--</option>";
				 	$.each(data, function(index, value){
									BigClassList+="<option value='"+value.bigClassNo+"'>"+value.bigClassName+"</option>";	
					});						
					$("#adminAuctionUpdateForm select[name=selBigClass]").html(BigClassList); 
			}//success
		});//ajax		
		$.ajax({
			type:"post",
			url:"${initParam.root}auction/getSmallClassList.do",
			datatype:"json",
			data:"bigClass=${vo.bcvo.bigClassNo}",
			success:function(data){	
				var smallClassList="<option value='${vo.scvo.smallClassNo}'>--${vo.scvo.smallClassName}--</option>";
				  	 
				$.each(data, function(index, value){
					smallClassList+="<option value='"+value.smallClassNo+"'>"+value.smallClassName+"</option>";
				});						
				$("#adminAuctionUpdateForm select[name=selSmallClass]").html(smallClassList); 
			}//success
		});//ajax
		 $("#adminAuctionUpdateForm select[name=selBigClass]").change(function(){		
		    		var bigClass = $("#adminAuctionUpdateForm select[name=selBigClass]").val();
					$.ajax({
							type:"post",
							url:"${initParam.root}auction/getSmallClassList.do",
							datatype:"json",
							data:"bigClass="+bigClass,
							success:function(data){						
								var smallClassList="<option value=''>--소분류--</option>"; 	 
								$.each(data, function(index, value){
									smallClassList+="<option value='"+value.smallClassNo+"'>"+value.smallClassName+"</option>";
								});						
								$("#adminAuctionUpdateForm select[name=selSmallClass]").html(smallClassList); 
							}//success
					});//ajax
		});//change
		$("#adminAuctionUpdateForm select[name=selSmallClass]").change(function(){
		var smallClassNo = $("#adminAuctionUpdateForm select[name=selSmallClass]").val();
		alert("smallClassNo "+smallClassNo);
		$("#adminAuctionUpdateForm :input[name=smallClassNo]").val(smallClassNo);
		});//change
		$("#adminAuctionUpdateForm").submit(function(){
			 if($("#auctionPrice").val()<$("#buyPrice").val()){
				 alert("즉시 구매 보다 경매가 커야 합니다. ");
				 return false;
			 }
			 if($("#selBigClass").val()==""){
				  alert("카테고리 선택 ");
				  return false;
			 }else if($("#selSmallClass").val()==""){
				 alert("소분류 선택 ");
				  return false;
			 }else if($("#boardTitle").val()==""){
				 alert("제목 입력");
				  return false;
			 }else if($("#boardContent").val()==""){
				 alert("내용 입력");
				return false;
			 }else if($("#boardContent").val()==""){
				 alert("내용 입력");
				  return false;
			 }else if($("#auctionPrice").val()==""){
				 alert("경매가 입력");
				  return false;
			 }else if($("#auctionTime").val()==""){
				 alert("시간 선택 ");
				  return false;
			 }else if($("#buyPrice").val()==""){
				 alert("즉시구매가 입력 ");
				  return false;
			 }else if($("#quantity").val()==""){
				 alert("수량 입력 ");
				  return false;
			 }
		});	
});

</script>




<form id="adminAuctionUpdateForm"  action="${initParam.root}auction/auctionUpdate.do" method="post">
	<input type="hidden" id="boardNo" name="boardNo" value="${vo.avo.boardNo}">
	 <input type="hidden" id="memberNo" name="memberNo" value="${vo.mvo.memberNo}">
	<input type="hidden" id="smallClassNo" name="smallClassNo" value="${vo.scvo.smallClassNo}">
	<input type="hidden" id="timePosted" name="timePosted" value="${vo.avo.timePosted}">




	<table border="1">
		<tr>
			<td>카테고리</td>
			<td><select id="selBigClass" name="selBigClass">

			</select> <select id="selSmallClass" name="selSmallClass">

			</select> 
			</td>
		</tr>
		<tr>
			<td>게시물 제목</td>
			<td><input type="text" name="boardTitle" id="boardTitle"
				value="${vo.avo.boardTitle}"></td>
		</tr>
		<tr>
			<td>내용</td>
			<td><textarea rows="20" cols="50" name="boardContent"
					id="boardContent">${vo.avo.boardContent}</textarea></td>
		</tr>
		<tr>
			<td>경매가</td>
			<td><input type="text" id="auctionPrice" name="auctionPrice"
				value="${vo.avo.auctionPrice}"></td>
		</tr>
		<tr>
			<td>경매시간</td>
			<td><select id="auctionTime" name="auctionTime">
					<c:choose>
						<c:when test="${vo.avo.auctionTime==1}">
							<option value="1" selected="selected">1일</option>
							<option value="3">3일</option>
							<option value="7">7일</option>
						</c:when>
						<c:when test="${vo.avo.auctionTime==3}">
							<option value="1">1일</option>
							<option value="3" selected="selected">3일</option>
							<option value="7">7일</option>
						</c:when>
						<c:otherwise>
							<option value="1">1일</option>
							<option value="3">3일</option>
							<option value="7" selected="selected">7일</option>
						</c:otherwise>
					</c:choose>
			</select></td>
		</tr>
		<tr>
			<td>즉시구매가</td>
			<td><input type="text" id="buyPrice" name="buyPrice"
				value="${vo.avo.buyPrice}"></td>
		</tr>
		<tr>
			<td>수량</td>
			<td><input type="text" id="quantity" name="quantity"
				value="${vo.avo.quantity}"></td>

		</tr>
		<tr>
			<td colspan="2"><input type="submit" value="수정"></td>
		</tr>


	</table>
</form>